import os
import yaml

#获取项目的根路径
def get_object_path():
    return os.path.abspath(os.getcwd().split('common')[0])

#读取config.yml文件
def read_config_file(one_node,two_node):
    with open(get_object_path()+'\\data'+'\\config.yaml',encoding='utf-8') as f:
        value = yaml.load(stream=f,Loader=yaml.FullLoader)
        return value[one_node][two_node]

#读取extract,yaml文件
def read_extract_file(one_node):
    with open(get_object_path()+'/logs'+'/extract.yaml',encoding='utf-8',mode='r') as f:
        value = yaml.load(stream=f,Loader=yaml.FullLoader)
        return value[one_node]

#写入extract,yaml文件 追加
def write_extract_file(data):
    with open(get_object_path()+'/logs'+'/extract.yaml',encoding='utf-8',mode='a') as f:
        yaml.dump(data, stream=f,allow_unicode=True)

#情况extract,yaml文件 清空
def clear_extract_file():
    with open(get_object_path()+'/logs'+'/extract.yaml',encoding='utf-8',mode='w') as f:
        f.truncate()


if __name__ == '__main__':
    print(get_object_path()+'data\\'+'config.yaml')
    print(read_config_file('home','base_url'))
